<template>
	<view class="main">
		<view class="logo"></view>
		<view class="logo-title">爆爆BOX</view>
		<view class="authorization-box" @click="getLogin">
			<view class="authorization-desc">我已阅读同意<text>《用户协议》</text>和<text>《隐私条款》</text></view>
			<button hover-class="none" class="submitInfo" open-type="getPhoneNumber"
				@getphonenumber="getToken">微信一键登录</button>
		</view>
		<view class="change-way">手机号登录</view>
	</view>
</template>

<script>
	let {
		getTokenInfo
	} = uni.$http.user
	export default {
		data() {
			return {
				logingCode: null
			};
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: '一键授权'
			})
		},
		methods: {
			getLogin() {
				// #ifndef H5
				uni.login({
					success: res => {
						this.logingCode = res.code
					},
				})
				// #endif
			},
			getToken(e) {
				let phoneCode = e.detail.code
				getTokenInfo({
					loginCode: this.logingCode,
					phoneCode
				}).then(res => {
					this.$store.dispatch('login', {
						accessToken: res.data
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
		color: #333;
	}

	.main {
		padding-top: 100rpx;
	}

	.logo {
		width: 200rpx;
		height: 200rpx;
		border-radius: 24rpx;
		background: #FF7803;
		margin: 0 auto;
	}

	.logo-title {
		margin-top: 32rpx;
		font-size: 36rpx;
		text-align: center;
		font-weight: bold;
	}

	.authorization-box {
		.authorization-desc {
			line-height: 56rpx;
			margin-top: 106rpx;
			font-size: 24rpx;
			text-align: center;

			& text {
				color: #FF7803;
			}
		}

		.submitInfo {
			display: block;
			width: 524rpx;
			height: 88rpx;
			margin: 14rpx auto 0 auto;
			text-align: center;
			line-height: 88rpx;
			box-sizing: border-box;
			color: #07C160;
			font-size: 34rpx;
			font-weight: 500;
			border: 2rpx solid rgba(0, 0, 0, 0.1);
			border-radius: 44rpx;
		}
	}

	.change-way {
		margin-top: 96rpx;
		line-height: 44rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #9E9E9E;
		text-align: center;
	}
</style>